import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [
  // 一级路由
  {
    path: '/index',
    component: () => import('../pages/index.vue'),
    // 二级路由
    children: [
      {
        path: '/home',
        component: () => import('../views/home.vue'),
        meta: {
          title: "首页"
        }
      },
      {
        path: '/cart',
        component: () => import('../views/cart.vue'),
        meta: {
          title: "购物车"
        }
      },
      {
        path: '/cate',
        component: () => import('../views/cate.vue') ,
        meta: {
          title: "分类"
        }
      },
      {
        path: '/mine',
        component: () => import('../views/mine.vue'),
        meta:{
          title:"个人中心"
        }
      },
      {
        path: '',
        redirect: '/home'
      }
    ]
  },
  {
    path:'/detail',
    component:()=>import('../pages/detail.vue'),
    meta: {
      title: "商品详情"
    }
  },
  {
    path:'/list',
    component:()=>import('../pages/list.vue'),
    meta: {
      title: "商品列表"
    }
  },
  {
    path:'/order',
    component:()=>import('../pages/order.vue'),
    meta: {
      title: "确认订单"
    }
  },
  {
    path:'/address',
    component:()=>import('../pages/address.vue'),
    meta: {
      title: "地址管理"
    }
  },
  {
    path:'/Addressadd',
    component:()=>import('../pages/Addressadd.vue'),
    meta: {
      title: "新增地址"
    }
  },
   {
    path:'/payment',
    component:()=>import('../pages/payment.vue'),
    meta: {
      title: "支付页面"
    }
  },
  {
    path:'/login',
    component:()=>import('../pages/login.vue'),
    meta: {
      title: "登录"
    }
  },
  {
    path:'/register',
    component:()=>import('../pages/register.vue'),
    meta: {
      title: "注册"
    }
  },
  {
    path: '*',
    redirect: '/index'
  }
]

const router = new VueRouter({
   //历史模式
  base: process.env.BASE_URL, // 环境地址 
  routes,
   //滚动行为
   scrollBehavior(to, from, position) {
    console.log(position, 'x,y的位置');
    //初始的时候position 默认是null 当我返回的时候，它会记录Y的位置，我们把记录的位置进行一个返回就可以了
    if (position) {
      return position
    } else {
      return {
        x: 0,
        y: 0
      }
    }
  }
})

export default router
